import { defineStore } from "pinia";

export const Showroom3DStore = defineStore("Showroom3D", {
  state() {
    return {
      projectId: "",
      sceneId: "",
      modelId: "",
      modelObj: {},
      modelList: [],
      editStatus: true,
      sceneIndex: 0,
      operationStatus: "",
      modelTemplateList: [],
    };
  },
  getters: {},
  actions: {
    setModelTemplateList(arr) {
      this.modelTemplateList = arr;
    },
    setProjectId(id) {
      this.projectId = id;
    },
    setSceneId(id) {
      this.sceneId = id;
    },
    setModelId(id) {
      this.modelId = id;
      const m = this.modelList.find((item) => this.modelId === item.modelId);
      this.modelObj = m === undefined ? modelList[0] : m;
    },
    addModel(obj) {
      this.modelList.push(obj);
    },
    deleteModel() {
      const index = this.modelList.findIndex((item) => item.modelId === this.modelId);
      console.log("this.modelId->", this.modelId, index);
      this.modelList.splice(index, 1);
    },
    setModelList(arr) {
      this.modelList = arr;
    },
    setEditStatus() {
      console.log("setEditStatus");
      this.editStatus = !this.editStatus;
    },
    setSceneIndex(index) {
      this.sceneIndex = index;
    },
    setOperationStatus(str) {
      this.operationStatus = str;
    },
  },
});
